const mongoose = require('mongoose')

// const connectDb = async()=>{
//   await mongoose.connect("mongodb://localhost:27017/huiwen");
//   console.log('connected!');
// };

// connectDb();

//连接数据库
//mongoose.connect('mongodb://数据库ip:端口号/数据库名'，{useMongoClient: true})
//  - 端口默认27017可省略
require('./schema/user')
const user = new Users({
  username: 'Alice',
  password: 'psw',
  fullname: 'Alice Full',
  phone: '110',
  email: 'alice@qq.com'
})
mongoose
  .connect('mongodb://127.0.0.1:27017/huiwen', { useNewUrlParser: true })
  .then(() => {
    console.log('MongoDB connected...')
    user.save().then(()=>{
      console.log('Data saved!')
    }).catch((err)=>{
      console.log('Data save err:' + err)
    })
  })
  .then(async ()=>{
    console.log('Query data...')
    var they = await Users.find();
    console.log(they);
  })
  .catch((err) => {
    console.log(err)
  })
